package cn.io0288.blog2.utils;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

public class DateUtils {
    public static String timeStamp2Date(Long timeStamp) {
        // 假设这是你的时间戳
//        long timeStamp = System.currentTimeMillis();

        if (timeStamp < 999999999999L) {
            timeStamp *= 1000;
        }
        // 将时间戳转换为Instant对象
        Instant instant = Instant.ofEpochMilli(timeStamp);

        // 将Instant对象转换为LocalDateTime对象
        LocalDateTime dateTime = instant.atZone(ZoneId.systemDefault()).toLocalDateTime();

        // 创建一个DateTimeFormatter对象，用于格式化日期
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        // 将LocalDateTime对象格式化为字符串 输出
        return dateTime.format(formatter);
    }

    public static int timeStamp2Day(Long timeStamp) {
        return (int) (timeStamp / 60 / 60 / 24);
    }
}
